package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihuRpc/internal/svc"
	"zhihu/zhihuRpc/zhihuRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type QuestionShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQuestionShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuestionShowLogic {
	return &QuestionShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QuestionShowLogic) QuestionShow(in *zhihuRpc.QuestionShowRequest) (*zhihuRpc.QuestionShowResponse, error) {
	// todo: add your logic here and delete this line

	var question mysql.Question
	mysql.DB.Debug().Where("id = ?", in.QuestionId).Find(&question)

	question.Hot = question.Hot + 1

	mysql.DB.Debug().Updates(&question)

	return &zhihuRpc.QuestionShowResponse{
		QuestionId: int64(question.ID),
		Content:    question.Content,
		UserId:     question.UserId,
	}, nil
}
